//
//  LoanViewController.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/8/29.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "LoanViewController.h"
#import "HP_LoanTableViewCell.h"
#import "Loan_ApplyViewController.h"
#import "LoanRequestTools.h"
#import "LoanModel.h"
#import "Loan_h5WebViewController.h"

#define BaseColor HexColor(0xBA915E)
#define NormalColor HexColor(0x999999)

@interface LoanViewController ()<UITableViewDelegate,UITableViewDataSource,HP_LoanTableViewCellDelegate>
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UIButton *defineBtn;//综合
@property(nonatomic,strong)UIButton *limitBtn;//额度
@property(nonatomic,strong)UIButton *speedBtn;//贷款速度
@property(nonatomic,strong)UIButton *loanInterestBtn;//贷款利息

@property(nonatomic,strong)UIView *line1;
@property(nonatomic,strong)UIView *line2;
@property(nonatomic,strong)UIView *line3;
@property(nonatomic,strong)UIView *line4;

@property(nonatomic,strong)UITableView *myTableView;


@property(nonatomic,assign)NSInteger pageNum;//页码数
@property(nonatomic,assign)NSInteger pageSize;//每页数量
@property(nonatomic,strong)NSString *sortfield;//排序字段 (loanLimit|term|rate) 代表按 额度|分期|利率 排序

@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic,strong)NSString *total;
@end

@implementation LoanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = @"贷款超市";
    self.pageSize = 10;
    self.pageNum = 1;
    self.sortfield = @"";
    [self.view addSubview:self.headerView];
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.myTableView.backgroundColor = ListMaoBackgroundColor;
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.myTableView registerClass:[HP_LoanTableViewCell class] forCellReuseIdentifier:@"HP_LoanTableViewCell"];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.headerView.mas_bottom);
        make.bottom.mas_equalTo(self.view).offset(0);
    }];
    
    HFQMJRefreshHeader *header = [HFQMJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(getListData)];
    self.myTableView.mj_header = header;
    self.myTableView.mj_footer = [HFQMJRefreshFooter footerWithRefreshingTarget:self refreshingAction:@selector(updateMoreHistoryCodeInfo)];
   
    [self updateListData];
    
}

-(void)getListData{
    self.pageSize = 10;
    self.pageNum = 1;
    [self.dataArr removeAllObjects];
    [self.myTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
    [self updateListData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    
}

-(void)updateMoreHistoryCodeInfo{
    
    if (self.dataArr.count < [self.total integerValue]) {
        self.pageNum = self.pageNum +1;
        [self updateListData];
    }else{
        [self.myTableView.mj_footer endRefreshingWithNoMoreData];
    }
    
}

- (void)updateListData {
    
    NSDictionary *param_dic = @{@"pageNum":@(self.pageNum),
                                @"pageSize":@(self.pageSize),
                                @"sortfield":self.sortfield
                                
                                };
    
    NSLog(@"----参数-----%@",param_dic);
    [HFQIndicationView showInView:self.view];
    __weak typeof (self)weakSelf = self;
    [LoanRequestTools LoanSupermarkerProductWithParameters:param_dic Success:^(id  _Nullable responseObject) {
        
        [weakSelf.myTableView.mj_header endRefreshing];
        [weakSelf.myTableView.mj_footer endRefreshing];
        [HFQIndicationView dismiss];
        
        if ([[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"code"]] isEqualToString:@"200"]) {
            
            NSArray *itemArray = responseObject[@"data"][@"rows"];
            self.total = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"total"]];
            for (NSDictionary *dic in itemArray) {
                LoanModel *model = [[LoanModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [self.dataArr addObject:model];
            }
            
            [self.myTableView reloadData];
        }
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        [weakSelf.myTableView.mj_header endRefreshing];
        [weakSelf.myTableView.mj_footer endRefreshing];
        [HFQIndicationView dismiss];
    }];
}

-(void)defineBtnAction{
    self.defineBtn.selected = YES;
    self.line1.hidden = NO;
    self.limitBtn.selected = NO;
    self.line2.hidden = YES;
    self.speedBtn.selected = NO;
    self.line3.hidden = YES;
    self.loanInterestBtn.selected = NO;
    self.line4.hidden = YES;
    
    self.pageSize = 10;
    self.pageNum = 1;
    self.sortfield = @"";
    [self getListData];
    
}
-(void)limitBtnAction{
    self.defineBtn.selected = NO;
    self.line1.hidden = YES;
    self.limitBtn.selected = YES;
    self.line2.hidden = NO;
    self.speedBtn.selected = NO;
    self.line3.hidden = YES;
    self.loanInterestBtn.selected = NO;
    self.line4.hidden = YES;
    
    self.pageSize = 10;
    self.pageNum = 1;
    self.sortfield = @"loanLimit";
    [self getListData];
    
}
-(void)speedBtnAction{
    self.defineBtn.selected = NO;
    self.line1.hidden = YES;
    self.limitBtn.selected = NO;
    self.line2.hidden = YES;
    self.speedBtn.selected = YES;
    self.line3.hidden = NO                  ;
    self.loanInterestBtn.selected = NO;
    self.line4.hidden = YES;
    
    self.pageSize = 10;
    self.pageNum = 1;
    self.sortfield = @"term";
    [self getListData];
    
}
-(void)loanInterestBtnAction{
    self.defineBtn.selected = NO;
    self.line1.hidden = YES;
    self.limitBtn.selected = NO;
    self.line2.hidden = YES;
    self.speedBtn.selected = NO;
    self.line3.hidden = YES;
    self.loanInterestBtn.selected = YES;
    self.line4.hidden = NO;
    
    self.pageSize = 10;
    self.pageNum = 1;
    self.sortfield = @"rate";
    [self getListData];
    
}

-(void)pushH5Action:(LoanModel *)model{
    Loan_h5WebViewController *h5Controller = [[Loan_h5WebViewController alloc]init];
    h5Controller.url = model.app_h5_link;
    h5Controller.imageUrl = model.productImg;
    h5Controller.titleName = model.productName;
    [self.navigationController pushViewController:h5Controller animated:YES];
    
    
}

#pragma mark ---------tableViewDelegate---------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HP_LoanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HP_LoanTableViewCell" forIndexPath:indexPath];
    cell.monthlyRateLabel.textColor = ThemeMaoRedColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    if (self.dataArr.count != 0) {
        LoanModel *model = self.dataArr[indexPath.section];
        [cell updateUIWithModel:model];
    }
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 10;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 10;
    }
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 122;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = ListMaoBackgroundColor;
    return view;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = ListMaoBackgroundColor;
    return view;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //h5跳转
}

-(UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidthMao, 45)];
        
        CGFloat space  = (ScreenWidthMao-(30+30+60+60))/5;
        _defineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_defineBtn setTitle:@"综合" forState:UIControlStateNormal];
        [_defineBtn setTitleColor:BaseColor forState:UIControlStateSelected];
        [_defineBtn setTitleColor:NormalColor forState:UIControlStateNormal];
        _defineBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _defineBtn.frame = CGRectMake(0, 0, space*1.5+30, 45);
        [_defineBtn addTarget:self action:@selector(defineBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.headerView addSubview:self.defineBtn];
        
        _line1 = [[UIView alloc]init];
        _line1.backgroundColor = BaseColor;
        [self.headerView addSubview:_line1];
        [_line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.defineBtn.mas_bottom);
            make.centerX.mas_equalTo(self.defineBtn);
            make.width.mas_offset(@(32));
            make.height.mas_offset(@2);
        
        }];
        
        _limitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_limitBtn setTitle:@"额度" forState:UIControlStateNormal];
        [_limitBtn setTitleColor:BaseColor forState:UIControlStateSelected];
        [_limitBtn setTitleColor:NormalColor forState:UIControlStateNormal];
        _limitBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _limitBtn.frame = CGRectMake(space*1.5+30, 0, space*1+30, 45);
        [_limitBtn addTarget:self action:@selector(limitBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.headerView addSubview:self.limitBtn];
        
        _line2 = [[UIView alloc]init];
        _line2.backgroundColor = BaseColor;
        [self.headerView addSubview:_line2];
        [_line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.limitBtn.mas_bottom);
            make.centerX.mas_equalTo(self.limitBtn);
            make.width.mas_offset(@(32));
            make.height.mas_offset(@2);
            
        }];
        
        _speedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_speedBtn setTitle:@"可贷时长" forState:UIControlStateNormal];
        [_speedBtn setTitleColor:BaseColor forState:UIControlStateSelected];
        [_speedBtn setTitleColor:NormalColor forState:UIControlStateNormal];
        _speedBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _speedBtn.frame = CGRectMake(space*2.5+60, 0, space*1+60, 45);
        [_speedBtn addTarget:self action:@selector(speedBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.headerView addSubview:self.speedBtn];
        
        _line3 = [[UIView alloc]init];
        _line3.backgroundColor = BaseColor;
        [self.headerView addSubview:_line3];
        [_line3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.speedBtn.mas_bottom);
            make.centerX.mas_equalTo(self.speedBtn);
            make.width.mas_offset(@(58));
            make.height.mas_offset(@2);
            
        }];
        
        _loanInterestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loanInterestBtn setTitle:@"贷款利息" forState:UIControlStateNormal];
        [_loanInterestBtn setTitleColor:BaseColor forState:UIControlStateSelected];
        [_loanInterestBtn setTitleColor:NormalColor forState:UIControlStateNormal];
        _loanInterestBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _loanInterestBtn.frame = CGRectMake(space*3.5+60+60, 0, space*1.5+60, 45);
        [_loanInterestBtn addTarget:self action:@selector(loanInterestBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.headerView addSubview:self.loanInterestBtn];
        
        _line4 = [[UIView alloc]init];
        _line4.backgroundColor = BaseColor;
        [self.headerView addSubview:_line4];
        [_line4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.loanInterestBtn.mas_bottom);
            make.centerX.mas_equalTo(self.loanInterestBtn);
            make.width.mas_offset(@(58));
            make.height.mas_offset(@2);
            
        }];
        
        self.defineBtn.selected = YES;
        self.line1.hidden = NO;
        self.line2.hidden = YES;
        self.line3.hidden = YES;
        self.line4.hidden = YES;
        
        
    }
    
    return _headerView;
}



-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc]init];
    }
    return _dataArr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
//
//
//#import "LoanViewController.h"
//#import "LoanRequestTools.h"
//#import <WebKit/WebKit.h>
//#import <JavaScriptCore/JavaScriptCore.h>
//
//@interface LoanViewController ()<WKNavigationDelegate, WKUIDelegate>
//
//@property (nonatomic,strong)WKWebView * webView;
//@property (strong, nonatomic) UIProgressView *progressView;
//
//@end
//
//@implementation LoanViewController
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//
//
//    self.view.backgroundColor = [UIColor whiteColor];
//    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://52.80.164.199:9097"]]];
//
//    self.title = @"借贷";
//}
//
//- (void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:animated];
//    self.webView.frame = self.view.frame;
//    //    [self updateListData];
//}
//
//- (void)updateListData {
//
//    [LoanRequestTools LoanSupermarkerProductWithParameters:nil Success:^(id  _Nullable responseObject) {
//
//    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
//
//    }];
//}
//
//
//- (void)initNavigationBarOne {
//
//    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
//    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//
//    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
//
//    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button1 setImage:[[UIImage imageNamed:@"BackArrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//    button1.frame = CGRectMake(0, 2.5, 30, 41.5f);
//    [button1 addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
//
//    [backgroundView addSubview:button1];
//
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backgroundView];
//}
//- (void)initNavigationBarTwo {
//
//    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
//    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//
//    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
//
//    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button1 setImage:[[UIImage imageNamed:@"BackArrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//    button1.frame = CGRectMake(0, 2.5, 30, 41.5f);
//    [button1 addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
//
//    [backgroundView addSubview:button1];
//
//    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button2 setImage:[[UIImage imageNamed:@"nav_close"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//    button2.frame = CGRectMake(30, 2.5, 30, 41.5f);
//    [button2 addTarget:self action:@selector(backRootAction) forControlEvents:UIControlEventTouchUpInside];
//
//    [backgroundView addSubview:button2];
//
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backgroundView];
//}
//
//#pragma mark -----WKNavigationDelegate---------
//// 页面开始加载时调用
//- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
//
//}
//// 当内容开始返回时调用
//- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
//
//}
//// 页面加载完成之后调用
//- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
//
//}
//// 页面加载失败时调用
//- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation {
//
//    NSLog(@"加载失败时调用的方法");
//    [HUD_Mao showCharacterMessage:@"加载失败，刷新重试"];
//}
//
//// 接收到服务器跳转请求之后调用
//- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
//
//}
//// 在收到响应后，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
//
//
//    decisionHandler(WKNavigationResponsePolicyAllow);
//}
//// 在发送请求之前，决定是否跳转
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
//
//    NSURL *URL = navigationAction.request.URL;
//
//    NSString *scheme = [URL scheme];
//
//    if ([scheme isEqualToString:@"tel"]) {
//
//        NSString *resourceSpecifier = [URL resourceSpecifier];
//
//        NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", resourceSpecifier];
//
//        /// 防止iOS 10及其之后，拨打电话系统弹出框延迟出现
//
//        dispatch_async(dispatch_get_main_queue(), ^{
//
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
//
//        });
//
//    }
//    decisionHandler(WKNavigationActionPolicyAllow);
//}
//// 计算wkWebView进度条
//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
//
//    if ([keyPath isEqualToString:@"estimatedProgress"]) {
//        CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
//        if (newprogress == 1) {
//            self.progressView.hidden = YES;
//            [self.progressView setProgress:0 animated:NO];
//        }else {
//            self.progressView.hidden = NO;
//            [self.progressView setProgress:newprogress animated:YES];
//        }
//    }else if ([keyPath isEqualToString:@"title"]) {
//
//        self.navigationItem.title = self.webView.title;
//
//        if(self.webView.backForwardList.backList.count > 0) {
//
//            self.tabBarController.tabBar.hidden = YES;
//            [self initNavigationBarOne];
//        }
//        if (self.webView.backForwardList.backList.count > 1) {
//
//            [self initNavigationBarTwo];
//        }
//
//    }else if ([keyPath isEqualToString:@"loading"]) {
//
//        NSLog(@"loading");
//    }
//}
//
//#pragma mark ----WKUIDelegate协议----
//
///**
// *  web界面中有弹出警告框时调用
// *
// *  @param webView           实现该代理的webview
// *  @param message           警告框中的内容
// *  @param frame             主窗口
// *  @param completionHandler 警告框消失调用
// */
//- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(nonnull WKFrameInfo *)frame completionHandler:(nonnull void (^)(void))completionHandler {    // js 里面的alert实现，如果不实现，网页的alert函数无效
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"
//                                                                             message:message
//                                                                      preferredStyle:UIAlertControllerStyleAlert];
//    [alertController addAction:[UIAlertAction actionWithTitle:@"确定"
//                                                        style:UIAlertActionStyleCancel
//                                                      handler:^(UIAlertAction *action) {
//                                                          completionHandler();
//                                                      }]];
//
//    [self presentViewController:alertController animated:YES completion:^{}];
//
//}
//
//- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler {
//    //  js 里面的alert实现，如果不实现，网页的alert函数无效  ,
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"
//                                                                             message:message
//                                                                      preferredStyle:UIAlertControllerStyleAlert];
//    [alertController addAction:[UIAlertAction actionWithTitle:@"确定"
//                                                        style:UIAlertActionStyleDefault
//                                                      handler:^(UIAlertAction *action) {
//                                                          completionHandler(YES);
//                                                      }]];
//    [alertController addAction:[UIAlertAction actionWithTitle:@"取消"
//                                                        style:UIAlertActionStyleCancel
//                                                      handler:^(UIAlertAction *action){
//                                                          completionHandler(NO);
//                                                      }]];
//
//    [self presentViewController:alertController animated:YES completion:^{}];
//
//}
//- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(nonnull WKFrameInfo *)frame completionHandler:(nonnull void (^)(NSString * _Nullable))completionHandler {
//
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:prompt message:nil preferredStyle:UIAlertControllerStyleAlert];
//
//    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//        textField.textColor = [UIColor blackColor];
//        textField.text = defaultText;
//    }];
//
//    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        completionHandler([[alert.textFields lastObject] text]);
//    }]];
//
//    [self presentViewController:alert animated:YES completion:NULL];
//}
//
//
//// 记得取消监听
//- (void)dealloc {
//    [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
//    [self.webView removeObserver:self forKeyPath:@"loading"];//移除kvo
//    [self.webView removeObserver:self forKeyPath:@"title"];
//}
//
//- (WKWebView *)webView {
//
//    if (!_webView) {
//        _webView = [[WKWebView alloc] initWithFrame:self.view.frame];
//        _webView.navigationDelegate = self;
//        _webView.UIDelegate = self;
//        [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
//        [_webView addObserver:self forKeyPath:@"loading" options:NSKeyValueObservingOptionNew context:nil];
//        [_webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
//
//        [self.view insertSubview:_webView belowSubview:self.progressView];
//    }
//    return _webView;
//}
//
//- (UIProgressView *)progressView {
//
//    if (!_progressView) {
//
//        _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
//        self.progressView.tintColor = HexColor(0x249FFA);
//        self.progressView.trackTintColor = [UIColor clearColor];
//        [self.view addSubview:self.progressView];
//    }
//    return _progressView;
//}
//
//-(void)goBack{
//
//    if([_webView canGoBack]){
//        [_webView goBack];
//    }else{
//        self.navigationItem.leftBarButtonItem = nil;
//        self.tabBarController.tabBar.hidden = NO;
//    }
//
//}
//- (void)backRootAction {
//
//    if (self.webView.backForwardList.backList.count > 1) {
//        [self.webView goToBackForwardListItem:self.webView.backForwardList.backList[0]];
//        self.navigationItem.leftBarButtonItem = nil;
//        self.tabBarController.tabBar.hidden = NO;
//    }else {
//        if([_webView canGoBack]){
//            [_webView goBack];
//        }else {
//            self.navigationItem.leftBarButtonItem = nil;
//            self.tabBarController.tabBar.hidden = NO;
//        }
//    }
//}
//
//
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
